package com.java.code.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author weichuanyuan
 * @e-mail wei.cy@bsoft.com.cn
 * @date 2022/2/11 16:24
 * @package com.java.code.aop
 * @description
 */
@Aspect
@Component
@Slf4j
@Order(2)
public class ExcuteTimeAspect {
    @Pointcut("@within(com.java.code.aop.ExcuteTimeAnnotation)")
    public void excuteTimePointCut()
    {
    }

    @Around("excuteTimePointCut()")
    public Object  aroundLog(ProceedingJoinPoint joinPoint) throws Throwable {
        long starttime = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();  //执行目标方法
        long exctime = System.currentTimeMillis() - starttime;
        log.info("执行时间："+exctime + "毫秒");
        return proceed;
    }
}
